<template>
  <el-row justify="center">
    <h1>***文库</h1>
  </el-row>
  <el-row>
    <el-col :span="3">
    </el-col>
    <el-col :span="18">
      <el-form :model="obj" class="demo-form-inline">
        <div style="display: flex;justify-content: space-around">
          <el-form-item style="width: 300px" label="标题:">
            <el-input v-model="obj.title"/>

          </el-form-item>
          <el-form-item label="类型">
            <el-select v-model="obj.type" class="showInfo">
              <el-option label="文学" value="文学"></el-option>
              <el-option label="科学" value="科学"></el-option>
              <el-option label="教育" value="教育"></el-option>
              <el-option label="笔记" value="笔记"></el-option>
            </el-select>
            {{ obj.value }}
          </el-form-item>
        </div>
        <span>内容:</span>
        <el-form-item>
          <div id="editor" ref="myEditor"></div>
          <slot></slot>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="add">提交</el-button>
          <el-button type="primary" @click="this.$router.push('/note/show')">返回首页</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <el-col :span="3">


    </el-col>

  </el-row>

</template>

<script>
import WangEditor from 'wangeditor'
import axios from "axios";
import {ElMessage} from 'element-plus'

export default {
  data() {
    return {
      obj: {},
    }
  },
  mounted() {
    const editor = new WangEditor('#editor')
    editor.create()
    this.editor = editor
  },
  methods: {
    add() {
      console.log(this.editor.txt.html());
      this.obj.info = this.editor.txt.html();
      console.log(this.obj)
      axios.post("/project/note/add",this.obj
      ).then(n => {
        if (n.data === "ok") {
          ElMessage({
            message: '添加成功',
            type: 'success',
          })
        }
      })
    }
  }
}
</script>
<style>
.w-e-menu {
  z-index: 2 !important;
}

.w-e-text-container {
  z-index: 1 !important;
}

.w-e-toolbar {
  z-index: 2 !important;
}


</style>